package com.yzt.message.activity;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.yzt.zhuju.base.BaseActivity;
import com.yzt.zhuju.network.entity.message.GroupUserControllerBean;
import com.yzt.zhuju.widget.tuiview.TUITextView;
import com.yzt.message.R;
import com.yzt.message.adapter.GroupUserControllerAdapter;
import com.yzt.p_base.utils.ToastUtil;

/**
 * 作者：bobwang
 * 创建时间：2023-11-19 23:06:16
 * 描述： 群成员操作页面
 */
public class GroupUserControllerActivity extends BaseActivity {

    private RecyclerView mMsgRecycler;

    private GroupUserControllerAdapter mAdapter;

    private TUITextView tv_confirm;

    @Override
    public int getLayoutId() {
        return R.layout.activity_group_user_controller;
    }

    @Override
    public void installViews() {
        ARouter.getInstance().inject(this);
        mTitleBar.setTitle("邀请好友");
        tv_confirm = findViewById(R.id.tv_confirm);
        mMsgRecycler = findViewById(R.id.recycler_view);
        mMsgRecycler.setHasFixedSize(true);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        mMsgRecycler.setLayoutManager(layoutManager);
        mAdapter = new GroupUserControllerAdapter();
        mMsgRecycler.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                GroupUserControllerBean bean = mAdapter.getItem(position);
                bean.setCheck(!bean.isCheck());
                mAdapter.notifyItemChanged(position);

                int i = 0;

                for (GroupUserControllerBean data : mAdapter.getData()) {
                    if (data.isCheck()) {
                        i++;
                    }
                }
                if (i > 0) {
                    tv_confirm.setText("邀请好友(" + i + ")");
                } else {
                    tv_confirm.setText("邀请好友");
                }
            }
        });
        tv_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int i = 0;

                for (GroupUserControllerBean data : mAdapter.getData()) {
                    if (data.isCheck()) {
                        i++;
                    }
                }
                if (i > 0) {
                    ToastUtil.showMessage("邀请好友");
                } else {
                    ToastUtil.showMessage("请选择想要邀请的好友");
                }
            }
        });
    }
}
